package io.jee.caisan.weixin.utils;

import org.springframework.ui.Model;

public class PageTools {

	public static final String HTML_ERROR = "common/error";
	public static final String HTML_SUCCESS = "common/success";
	public static final String KEY_MSG = "msg";
	public static final String KEY_URL = "url";
	public static final String KEY_BACK = "back";
	public static final String KEY_TIME = "time";
	
	
	public static String toSuccess(Model model, String message, String url) {
		return toSuccess(model, message, url, false, 0);
	}
	
	public static String toSuccess(Model model, String message, String url, boolean isBack, Integer time) {
		model.addAttribute(PageTools.KEY_MSG, message);
		model.addAttribute(PageTools.KEY_URL, url);
		model.addAttribute(PageTools.KEY_BACK, isBack);
		model.addAttribute(PageTools.KEY_TIME, time);
		return PageTools.HTML_SUCCESS;
	}
	
	public static String toError(Model model, String message, String url) {
		return toError(model, message, url, false, 0);
	}
	
	public static String toError(Model model, String message, String url, boolean isBack, Integer time) {
		model.addAttribute(PageTools.KEY_MSG, message);
		model.addAttribute(PageTools.KEY_URL, url);
		model.addAttribute(PageTools.KEY_BACK, isBack);
		model.addAttribute(PageTools.KEY_TIME, time);
		return PageTools.HTML_SUCCESS;
	}
	
}
